using System;
using MbUnit.Framework;
using DotNetNukeMVPWizard.ProjectConfiguration;

namespace DotNetNukeMVPWizard.Tests
{
    [TestFixture]
    public class TestSafeIdentifierConfiguration
    {
        #region Properties
        private IConfigurable Actual;

        private const string STR_SpecialSymbols = @"D@o+t^N!e~t`N'u;k$e(C)o=m{m}u[n]i-t,y";
        private const string STR_SpecialSymbols_Safe = "D_o_t_N_e_t_N_u_k_e_C_o_m_m_u_n_i_t_y";
        private const string STR_1LeadingNumber = "1LeadingNumber";
        private const string STR_1LeadingNumber_Safe = "_1LeadingNumber";
        private const string STR_WithSpaces = "With Spaces";
        private const string STR_WithSpaces_Safe = "With_Spaces";
        #endregion

        #region SetUp
        [SetUp]
        public void SetUp()
        {
            Actual = new SafeIdentifierConfiguration("Key");
        }
        #endregion

        // TODO: Add test for SafeIdentifierConfiguration.ErrorMessage

        #region Test Value_Set transformations and validation
        [Test]
        [Description("Ensure that spaces are replaced with underscores when the SafeIdentifierConfiguration Value is set")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void SafeIdentifierConfiguration_Should_Replace_Spaces_With_Underscores()
        {
            // Should_Replace_Spaces_With_Underscores
            Actual.Value = STR_WithSpaces;
            Assert.AreEqual(STR_WithSpaces_Safe, Actual.Value);
        }

        [Test]
        [Description("Ensure that leading numbers receive an underscore prefix when the SafeIdentifierConfiguration Value is set")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void SafeIdentifierConfiguration_Should_Place_Underscore_In_Front_Of_Leading_Number()
        {
            // Should_Place_Underscore_In_Front_Of_Leading_Number
            Actual.Value = STR_1LeadingNumber;
            Assert.AreEqual(STR_1LeadingNumber_Safe, Actual.Value);
        }

        [Test]
        [Description("Ensure that special symbols are replaced with underscores when the SafeIdentifierConfiguration Value is set")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void SafeIdentifierConfiguration_Should_Replace_Special_Symbols_With_Underscores()
        {
            // Should_Replace_Special_Symbols_With_Underscores
            //       @ + ^ ! ~ ` ' ; $ ( ) = { } [ ] - ,
            Actual.Value = STR_SpecialSymbols;
            Assert.AreEqual(STR_SpecialSymbols_Safe, Actual.Value);
        }

        [Test]
        [Row(@"Not/Allowed")]
        [Row(@"Not?Allowed")]
        [Row(@"Not:Allowed")]
        [Row(@"Not&Allowed")]
        [Row(@"Not\Allowed")]
        [Row(@"Not*Allowed")]
        [Row("Not\"Allowed")]
        [Row(@"Not<Allowed")]
        [Row(@"Not>Allowed")]
        [Row(@"Not|Allowed")]
        [Row(@"Not#Allowed")]
        [Row(@"Not%Allowed")]
        [Description("Ensure that IsValid returns false when the SafeIdentifierConfiguration Value is set to these prohibited characters")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void SafeIdentifierConfiguration_Should_Get_IsValid_False_For_Prohibited_Characters(string value)
        {
            // Should_Get_IsValid_False_For_Prohibited_Characters (prohibited by Visual Studio when creating the project)
            //      / ? : & \ * " < > | # %
            Actual.Value = value;
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Row(".")]
        [Row("..")]
        [Description("Ensure that IsValid returns false when the SafeIdentifierConfiguration Value is set to a single period (.) or a double-period (..)")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void SafeIdentifierConfiguration_Should_Get_IsValid_False_For_Current_Path_Name(string value)
        {
            // Should_Get_IsValid_False_For_Current_Path_Name
            //      .
            // Should_Get_IsValid_False_For_Parent_Path_Name
            //      ..
            Actual.Value = value;
            Assert.IsFalse(Actual.IsValid);
        }
        #endregion
    }
}
